package com.ziyia.a2_10_all;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.widget.Toast;

public class Menu1 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu1);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        SubMenu subMenu = menu.addSubMenu("字体大小");
        MenuItem item1 = subMenu.add(0, 10, 0, "10号字体");
        item1.setCheckable(true);

        MenuItem menu2 = subMenu.add(0, 20, 0, "20号字体");
        menu2.setCheckable(true);

        subMenu.add(0, 30, 0, "30号字体");
        subMenu.add(0, 40, 0, "40号字体");
        subMenu.add(0, 50, 0, "50号字体");

        MenuItem setIntent = menu.add("老基壳");
        setIntent.setIntent(new Intent(this, Menu3.class));

        SubMenu subMenu1 = menu.addSubMenu("字体颜色");
        subMenu1.add(0, 100, 0, "红色");
        subMenu1.add(0, 200, 0, "黑色");
        subMenu1.add(0, 300, 0, "白色");
        subMenu1.add(0, 400, 0, "蓝色");

        return super.onCreateOptionsMenu(menu);
    }


    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        int itemId = item.getItemId();
        item.setChecked(!item.isChecked());
        Toast.makeText(this, "" + itemId, Toast.LENGTH_SHORT).show();

        return false;
    }
}